#include <bits/stdc++.h>
// 2025/01/21
// tag: 
// Author: Zhang Muen
using namespace std;

int parents[201];
bool g[201][201];

class UF
{
public:
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 1; i <= n; i++)
            parents[i] = i;
    };

    int find(int i)
    {
        if (parents[i] != i)
            return find(parents[i]);
        return parents[i];
    }

    void un(int j, int i)
    {
        int rj = find(j);
        parents[i] = rj;
    }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    UF uf(n);
    for (int i = 1; i <= n; i++){
        int p;
        while (true){
            cin >> p;
            if (p == 0)
                break;
            g[i][p] = true;
        }
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                if (g[i][j] && g[j][k])
                    g[i][k] = true;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (g[i][j])
                uf.un(i, j);
    unordered_set<int> us;
    for (int i = 1; i <= n; i++)
        us.insert(uf.find(i));
    cout << us.size();
    return 0;
}